/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
func findMode(root *TreeNode) []int {
    res := []int{}
    if root == nil {
        return res
    }
    var preNode *TreeNode
    count := 1
    max := 1
    var traverse func (root *TreeNode) 
    traverse = func (root *TreeNode) {
        if root == nil {
            return
        }
        traverse(root.Left)
        if preNode != nil && root.Val == preNode.Val {
            count++
        } else {
            count = 1
        }
        if count >= max {
            if count > max && len(res) > 0{
                res = []int{root.Val}
            }else {
                res = append(res, root.Val)
            }
            max = count
        }
        preNode = root
        traverse(root.Right) 
    }
    traverse(root)
    return res
}